<?php 
include('./fun.php');include('./hd_fun.php');
$conn=my_sql($cfg);
$re=user_login();
if($re['err']=='no_login'){direct('login.php?t='.time());exit;}
if($re['err']!='ok'){die($re['err']);}
$user=$re['user'];
$shop_id=$re['shop_id'];
$shop=get_shop();
$set=get_set();
//订单
$time=time()-3600*24*30;
$sql='select id,state,date from '.$cfg['e'].'order where shop_id="'.$shop_id.'" and state in (1,2,5,80,99) and date>'.$time.' order by id asc';
$orders=db($sql);
if($orders){
foreach($orders as $v){
$order[$v['state']]++;
$d=date('m-d',$v['date']);
$oo[$d]++;
$lab[$d]='"'.$d.'"';
}
}
if(!$order[2]){$order[2]=0;}
if(!$order[5]){$order[5]=0;}
if(!$order[80]){$order[80]=0;}
$order[10]=$order[2]+$order[5];
$order[99]=$order[80]+$order[99];


//订单
$sql='select id,hd_title,total,pay_date,logo,nickname,num from '.$cfg['e'].'order where state=1  and shop_id="'.$shop_id.'" order by id desc';
$no_send=db($sql);

$sql='select id,date from '.$cfg['e'].'shop_gz where shop_id="'.$shop['id'].'" and date>'.$time.' order by id asc';
$users=db($sql);
if($users){
foreach($users as $v){
$d=date('m-d',$v['date']);
$uu[$d]+=2;
if(!$oo[$d]){$oo[$d]=0;}
$lab[$d]='"'.$d.'"';

}
}

if($lab){ksort($lab);}
if($oo){ksort($oo);}
if($uu){ksort($uu);}


?>
<style>

main_box{float:left;width:100%;height:100%;}
info_box{float:left;width:100%;height:500px;padding-right:400px;padding-left:10px;margin-top:10px}
right{position:absolute;right:20px;top:10px;z-index:100;height:480px;width:370px;background:#fff;padding-top:40px}
right handle{width:100%;height:20px;line-height:20px;position:absolute;left:0;top:10px;font-size:16px;font-weight:bold;padding-left:10px;}


left_box{float:left;width:100%;display:flex;flex-direction:row;}
left_box boxx{float:left;width:100%;height:120px;background:#fff;display:flex;flex-direction:row;}
left_box ibox{float:left;padding:10px;width:100%;}
ibox itemx{float:left;width:100%;text-align:center;height:100%;padding-top:30px}
ibox num{float:left;width:100%;height:30px;line-height:30px;font-size:45px;font-weight:bold;}
ibox text{float:left;width:100%;}
chart_box{float:left;width:100%;height:360px;padding:10px}
chart_box chart{float:left;width:100%;height:100%;background:#fff}

order_box{float:left;width:100%;height:100%;font-size:13px;padding:10px;overflow:hidden;overflow-y:auto;padding-top:0px;padding-bottom:0}

order_item{float:left;width:100%;height:70px;padding-left:70px;margin-top:5px;border-bottom:1px solid #eee;}
order_item img{position:absolute;width:50px;height:50px;border-radius:50%;left:5px;top:5px}
order_item hd_title{float:left;width:100%;height:16px;line-height:16px;overflow:hidden;margin-top:5px}
order_item nickname{float:left;width:100%;height:16px;line-height:16px;}
order_item info{float:left;width:100%;}
order_item info x{float:right;color:crimson;font-size:17px}

</style>
<main_box>
<hh><b>欢迎使用<?php echo $set['webname']?></b></hh>

<info_box>
<left_box>
<ibox>
<boxx >
<itemx><num><?php echo ($order[1]?$order[1]:0)?></num><text>待发货</text></itemx>
<itemx><num><?php echo ($order[10]?$order[10]:0)?></num><text>待收货</text></itemx>
<itemx><num><?php echo ($order[99]?$order[99]:0)?></num><text>售后</text></itemx>
</boxx></ibox>

<ibox>
<boxx >
<itemx><num><?php echo $shop['hd_num']?></num><text>活动数</text></itemx>
<itemx><num><?php echo $shop['people_num']?></num><text>关注人数</text></itemx>
<itemx><num><?php echo $shop['order_num']?></num><text>订单数</text></itemx>
</boxx></ibox>
</left_box>

<chart_box>
<chart >
<canvas id="order" style="float:left;width:100%;height:100%;"></canvas>
</chart>
</chart_box>


<right><handle>最新订单</handle>
<order_box>
<?php 
if($no_send){
foreach($no_send as $v){
echo '<order_item>
<img src="'.$v['logo'].'">
<hd_title>'.base64($v['hd_title']).'</hd_title>
<nickname>'.base64($v['nickname']).'</nickname>
<info>共'.$v['num'].'件<x>￥'.$v['total'].'</x></info>
';

echo '</order_item>';
}


}else{echo '暂时没有订单';}

?>


</order_box>
</right>
</info_box>




</main_box>







<script>
    
var ctx = document.getElementById('order');
var myChart = new Chart(ctx, {
    type: 'line',responsive: true,plugins: {
      title: {
        display: true,
        text: '月订单情况'
      },
    },
    data: {
        labels: [<?php if($lab){echo implode(',',$lab);}?>],
        datasets: [{
            label: '订单数',
            data: [<?php if($oo){echo implode(',',$oo);}?>],
            backgroundColor: [
                'rgba(255, 99, 132, 0.2)',
                'rgba(54, 162, 235, 0.2)',
                'rgba(255, 206, 86, 0.2)',
                'rgba(75, 192, 192, 0.2)',
                'rgba(153, 102, 255, 0.2)',
                'rgba(255, 159, 64, 0.2)'
            ],
            borderColor: [
                'rgba(255, 99, 132, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(255, 206, 86, 1)',
                'rgba(75, 192, 192, 1)',
                'rgba(153, 102, 255, 1)',
                'rgba(255, 159, 64, 1)'
            ],
            borderWidth:2,
            tension: 0.2
        },
        
        {
            label: '用户注册',
            data: [<?php if($uu){echo implode(',',$uu);}?>],
            backgroundColor: [
                
                'rgba(54, 162, 235, 0.2)',
                
            ],
            borderColor: [
               
                'rgba(54, 162, 235, 1)',
                
            ],
            borderWidth:2,
            tension: 0.2
        }
        
        ]
    },
    options: {
        scales: {
            y: {
                beginAtZero: true
            }
        }
    }
});



</script>